package com.enjoyor.soa.traffic.rest.efoms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.efoms.DeviceWranInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.WranTacticsInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IDeviceWranInfoConsumeService;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IWranTacticsConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Auth
@RestController
@RequestMapping({ "/tactics" })
@Api("报警策略rest接口")
@CrossOrigin
public class WranTacticsController {
	@Autowired
	private IWranTacticsConsumeService wranTacticsConsumeService;

	@GetMapping(value = { "getWranTacticsById" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("根据编号查询报警策略信息")
	@ApiImplicitParam(name = "tacticsId", value = "报警策略编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo getWranTacticsById(
			@RequestParam(defaultValue = "", value = "tacticsId", required = false) String tacticsId,
			HttpServletRequest request) {
		return wranTacticsConsumeService.selectWranTacticsById(tacticsId);
	}
	
	@GetMapping(value = { "getWranTacticsList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("查询报警策略列表信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "tacticsId", value = "报警策略编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "tacticsLevelCode", value = "策略等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranTypeCode", value = "报警类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranLevelCode", value = "报警等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String")})
	public ResultPojo getWranTacticsList(
			@RequestParam(defaultValue = "", value = "tacticsId", required = false) String tacticsId,
			@RequestParam(defaultValue = "", value = "tacticsLevelCode", required = false) String tacticsLevelCode,
			@RequestParam(defaultValue = "", value = "wranTypeCode", required = false) String wranTypeCode,
			@RequestParam(defaultValue = "", value = "wranLevelCode", required = false) String wranLevelCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "devId", required = false) String devId,
			HttpServletRequest request) {
		return wranTacticsConsumeService.selectWranTacticsList(tacticsId, tacticsLevelCode, wranTypeCode, wranLevelCode,
				devTypeCode, devId);
	}
	
	@PostMapping(value = { "/insertWranTacticsInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("新增报警策略信息")
	public ResultPojo insertWranTacticsInfo(
    		@RequestBody WranTacticsInfoDto wranTacticsInfoDto, HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
		return wranTacticsConsumeService.insertWranTacticsInfo(wranTacticsInfoDto, username);
	}
	
	@PutMapping(value = { "/updateWranTacticsInfo" }, consumes = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("更新报警策略信息")
    public ResultPojo updateWranTacticsInfo(
    		@RequestBody WranTacticsInfoDto wranTacticsInfoDto, HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
        return wranTacticsConsumeService.updateWranTacticsInfo(wranTacticsInfoDto, username);
    }
	
	@DeleteMapping(value = { "/deleteWranTacticsInfo" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除报警策略信息")
    @ApiImplicitParam(name = "tacticsId", value = "报警策略编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo deleteWranTacticsInfo(
    		@RequestParam(defaultValue = "", value = "tacticsId", required = true) String tacticsId,
    		HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
        return wranTacticsConsumeService.deleteWranTacticsInfo(tacticsId, username);
    }
	
}
